#!/bin/sh
#
# This file is part of OpenMediaVault.
#
# @license   http://www.gnu.org/licenses/gpl.html GPL Version 3
# @author    Volker Theile <volker.theile@openmediavault.org>
# @copyright Copyright (c) 2009-2021 Volker Theile
#
# OpenMediaVault is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# OpenMediaVault is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenMediaVault. If not, see <http://www.gnu.org/licenses/>.

# NOTE:
# If the machine does not run 24/7 it might happen that cron-apt is not
# executed. Because anacron does not execute cron jobs defined in /etc/cron.d
# (where the default cron-apt cron job file is located) this script ensures
# that cron-apt is executed at least once a day.

# Remove the '/etc/cron.d/cron-apt' file installed by the cron-apt package.
rm -rf /etc/cron.d/cron-apt

# Download and install packages.
test -x /usr/sbin/cron-apt && /usr/sbin/cron-apt

# Send an email when a reboot is required.
if [ -e "/var/run/reboot-required" ]; then
    echo "A reboot of the system is required to complete a package upgrade." | mail -E -s "Reboot required" root
fi
